<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遍历对象</title>
    <script src="jquery.min.js"></script>
</head>

<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <script>
        $(function() {
            var arr = ['red', 'blue', 'pink'];
            let sum = 0;
            $('div').each(function(i, domEle) {
                    console.log(i); //打印出0 1 2
                    console.log(domEle); //打印出每个元素，这个参数是DOM对象
                    $(domEle).css('color', arr[i]);
                    sum += Number($(domEle).text());
                    console.log(sum);
                })
                // 2  .each()方法遍历元素，主要用来遍历数据，处理数据
            $.each($('div'), function(i, element) {
                console.log(i);
                console.log(element);
            })
            $.each(arr, function(i, ele) {
                console.log(i);
                console.log(ele);
            })
            $.each({
                name: 'ccj',
                age: 18
            }, function(i, ele) {
                console.log(i);
                console.log(ele);
            })
        });
    </script>
</body>

</html>